import {
	mapGetters,
	mapMutations,
	mapActions,
	mapState
} from 'vuex';

export default {
	computed: {},
	methods: {
		// 判断时间是否超过一个小时
		isMoreOneTime(time) {
			let a = new Date(time).getTime()
			let b = new Date().getTime()
			
			let hours = parseInt((a - b));
			
			if (hours > 3600000) {  // 超过
				return true
			} else {
				return false
			}
		},
		
		// 日期转时间戳
		getUnixTime(dateStr){
		    var date =  new Date(dateStr); 
		    var time_str = date.getTime().toString();
		    return time_str.substr(0, 10);
		},
		
		// 日期排序
		ReverseRankingDate(data, p) {
			if (data) {
				for (let i = 0; i < data.length - 1; i++) {
				    for (let j = 0; j < data.length - 1 - i; j++) {
				        if (Date.parse(data[j][p]) > Date.parse(data[j+1][p])) {
				            var temp = data[j];
				            data[j] = data[j + 1];
				            data[j + 1] = temp;
				        }
				    }
				}
				return data;
			}
		},
		
		//时间格式进行处理
		getTime(strtime) {
			let date = new Date(strtime.replace(/-/g, "/"));
			// date 预计送达时间戳
			date = Date.parse(date);
			// 转为国际标准时间
			let time = new Date(parseInt(date));
			// 一共相差几天
			let days = parseInt((date - new Date().getTime()) / 86400000);
			// 今天是几号
			let today = new Date().getDate();
			let mouth = time.getMonth() + 1;
			// 预计送达是几号
			let day = time.getDate();
			
			let hour = time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
			let min = time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes();
			// offset 送达日期-今天日期差
			let offset = Math.abs(day - today);
			let obj = {
				month: `${mouth}月${day}日`,
				// 转义
				date: "",
				// 具体时间
				time: hour + ":" + min,
			};
			
			// 这里双重判断，第一个判断days < 3是验证是否在同一个月，第二个offset < 3是判断是验证相差是几天
			if (days < 3 && offset < 3) {
				if (offset === 0) {
					obj.date = "今天";
				} else if (offset === 1) {
					obj.date = "明天";
				} else if (offset === 2) {
					obj.date = "后天";
				}
			} else {
				obj.date = mouth + "月" + day + "日"
			}
			return obj;
		},
		
		// 打开微信内置地图导航
		openLocation(latitude = (+this.cinemaData.latitude), longitude = (+this.cinemaData.longitude)) {
			console.log(latitude, longitude);
			uni.openLocation({
				latitude,
				longitude,
				success: function() {
					console.log('success');
				}
			});
		},
	},
}
